<template>
	<view class="news">
		<news-list @itemClick="goDetail" :list="newsList"></news-list>
	</view>
</template>

<script>
	import { reqNewsList } from '@/api'
	import newsList from '@/components/news-item/news-item'
	export default {
		data() {
			return {
				newsList: []
			};
		},
		onLoad() {
			this.getNewsList()
		},
		components:{
			'news-list': newsList
		},
		methods:{
			async getNewsList() {
				const result = await reqNewsList()
				if(result.code === 200) {
					this.newsList = result.data
				} else {
					uni.showToast({
						title: '获取失败'
					})
				}
			},
			// 跳转到详情页
			goDetail(id) {
				console.log(id)
				uni.navigateTo({
					url:`/pages/news-detail/news-detail?id=${id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	
</style>
